<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <rx-list-title :title="i18n('list.asyncTasks','异步任务')"></rx-list-title>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.taskName','任务名称')">
                            <a-input :placeholder="i18n('list.taskNamePlaceholder','请输入任务名称')" v-model="queryParam.Q_TASK_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-bpm/bpm/core/bpmAsyncTask/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >
                    <span slot="isSuccess" slot-scope="{ text, record }">
                        <a-tag :color="statusMap[text].color">
                            <span>{{ statusMap[text].text }}</span>
                        </a-tag>
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span  @click="detail(record)">{{$ti18('rxList.detailBtn','明细')}}</span>
                        <span v-show="record.isSuccess!='RUNNING'" @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                    <span slot="nodeName" slot-scope="{ text, record }">
                        {{$i18(text,"节点名称")}}
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import BpmAsyncTaskApi from '@/api/bpm/core/bpmAsyncTask'
import BpmAsyncTaskEdit from './BpmAsyncTaskEdit'
import {BaseList,RxFit,RxGrid } from '@lowcode/jpaas-common-lib';
import userState from "@/assets/js/userState";
export default {
    name: 'BpmAsyncTaskList',
    mixins: [BaseList,userState],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 40,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.taskName','任务名称'), dataIndex: 'taskName', width: 200},
                {title: this.i18n('form.nodeName','节点名称'), dataIndex: 'nodeName', width: 100},
                {title: this.i18n('form.isSuccess','执行结果'), dataIndex: 'isSuccess', width: 100,scopedSlots: {customRender: 'isSuccess'}},
                {title: this.i18n('form.createTime','执行时间'), dataIndex: 'createTime', width: 60},
                {title: this.$ti18('rxList.action','操作'), width: 50, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],
            component:BpmAsyncTaskEdit,
            comment:this.i18n("list.comment","异步任务记录"),
            widthHeight:['800px','600px'],
            fitSearch:false,
            statusMap: {
                "SUCCESS": {color: 'green', text: this.i18n("list.success","成功")},
                "ERROR": {color: 'red', text: this.i18n("list.error","失败")},
                "RUNNING": {color: 'blue', text: this.i18n("list.running","运行中")},
            },
        }
    },
    created() {
        this.queryParam["Q_CREATE_BY__S_EQ"]=this.user.userId;
    },
    methods:{
        i18n(name,text,key){
            return this.$ti18(name,text,"BpmAsyncTask",key);
        },
        delById(ids){
            return BpmAsyncTaskApi.del({ ids: ids.join(',') });
        },
        getListByParams(parameter){
            return BpmAsyncTaskApi.query(parameter)
        },
        cancel(){
            this.queryParam = {};
            this.queryParam["Q_CREATE_BY__S_EQ"] = this.user.userId;
            this.$nextTick(() => {
                this.$refs['table'].loadData();
            })
        }

    }
}
</script>
<style scoped>
.table-operator {
    padding:4px;
}
.table-operator button {
    margin:2px;
}
</style>

